#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdio.h>

int main() {
    int year = 0;
    int month = 0;
    int arr[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    while (scanf("%d %d", &year, &month) != EOF)
    {
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        {
            if (month == 2)
            {
                printf("%d\n", arr[month - 1] + 1);
            }
            else
                printf("%d\n", arr[month - 1]);
        }
        else
            printf("%d\n", arr[month - 1]);
    }
    return 0;
}